package untiring07.mvc.actions;

import java.io.IOException;
import java.rmi.ServerException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import untiring07.mvc.dao.BoardDAO;
import untiring07.mvc.model.BoardVO;

public class WriteBoardAction implements ActionHandler {

	@Override
	public String execute(HttpServletRequest req, HttpServletResponse res)
			throws ServerException, IOException {
		
		String viewPage = "f|/WEB-INF/jsp/tiles/mvc.jsp";
		
		String method = req.getMethod();
		
		if(method.equalsIgnoreCase("get")){
			req.setAttribute("action", "../board/write.jsp");
			System.out.println("writeBoardAtion이 get으로 호출");
			
		}else if(method.equalsIgnoreCase("post")){
			req.setAttribute("action", "../board/list.jsp");
			viewPage="r|listBoard.mvc";
			System.out.println("writeBoardAtion이 post으로 호출");
			req.setCharacterEncoding("UTF-8");
			BoardVO bvo = new BoardVO();
			bvo.setTitle(req.getParameter("title"));
			bvo.setUid(req.getParameter("uid"));
			bvo.setContents(req.getParameter("contents"));
			
			BoardDAO.writeBoard(bvo);
		}return viewPage;
	}

}
